<?php
## include required files
/*******************************/
require_once '../../includefiles.php';
include_once("../../model/users.php");
require_once '../../model/budget.php';
require_once '../../model/trade.php';
require_once '../../redirect.php';

## Create Objects
/*******************************/
$userObj = new Model_Users();
$budgetObj = new Model_Budget();
$objTrade = new Model_TRADE();
/*******************************/
if($_GET['ud']){
	$userId = base64_decode($_GET['ud']);
	$userDetArray = $userObj->getUserDetailsByUserId($userId);
//	echo "<pre>";print_r($userDetArray);exit;
	$smarty->assign('userDetArray',$userDetArray);
	
	$tradeid = $userDetArray['tradeid'];
	$tradeArray = explode(",",$tradeid);
	
	$jobTypes = $userDetArray['jobtype'];
	$jobArray = explode(",",$jobTypes);
	$tradeArrayNames = array();
	
	$i=0;
	foreach($tradeArray as $ta){
		$tradeName = $objTrade->getTradeNameById($ta);
		$tradeArrayNames[$i]['parent_id'] = $ta;
		$tradeArrayNames[$i]['tradeName'] = $tradeName;
		$tradeArrayNames[$i]['jobArr'] = array();	
		$i++;
	}
	
	$jobCnt = count($jobArray);
	$tCount = count($tradeArray);
	$j=0;
	for($k=0;$k<$tCount;$k++){
		for($l=0;$l<$jobCnt;$l++){
			$isItFromCat = $objTrade->checkJobTypesIsUnderTheParentCat($jobArray[$l],$tradeArrayNames[$k]['parent_id']);
				if(count($isItFromCat) > 0){
				$tradeArrayNames[$k]['jobArr'][$j]['jobType'] = $jobArray[$l];
				$tradeArrayNames[$k]['jobArr'][$j]['jobName'] = $isItFromCat['trade_category'];
				$j++;
			}
		}
		$j=0;
	}
	$smarty->assign('jobsArray',$tradeArrayNames);
//echo "<pre>";print_r($tradeArrayNames);
//exit;	
}else{
	@header("location:".SITE_URL);
	exit;
}

if($_POST['submit']){/*
$userId = base64_decode($_GET['ud']);	
//	echo "<pre>";print_r($_POST);exit;
	if($_POST['parentTradeId'] && $_POST['jobTypeId']){
		$tradeIds = implode(",",$_POST['parentTradeId']);
		$jobIds = implode(",",$_POST['jobTypeId']);
	}
	$updatesArray = array();
	$updatesArray['tradeid'] = $tradeIds;
	$updatesArray['jobtype'] = $jobIds;	
	$userObj->editUserValueById($updatesArray,$userId);*/
	@header("location:".SITE_URL."/register/registersuccess/");
	exit;
	
}


if($_SESSION['msg'] != ''){
	$smarty->assign("msg", $_SESSION['msg']);	
	unset($_SESSION['msg']);
}

$active ="myaccount";
$smarty->assign('active',$active);
$subactive ="myjobs";
$smarty->assign('subactive',$subactive);
$smarty->assign('mainmenu',"4");


$smarty->display(TEMPLATEDIR .'/modules/register/confirmation.tpl');
?>